export function showHud(message, duration = 2000) {
    // 创建容器元素
    const hudContainer = document.createElement('div');
    hudContainer.style.position = 'fixed';
    hudContainer.style.top = '0';
    hudContainer.style.left = '0';
    hudContainer.style.width = '100%';
    hudContainer.style.height = '100%';
    hudContainer.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
    hudContainer.style.display = 'flex';
    hudContainer.style.justifyContent = 'center';
    hudContainer.style.alignItems = 'center';
    hudContainer.style.zIndex = '9999';

    // 创建内容方块
    const hudContent = document.createElement('div');
    hudContent.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
    hudContent.style.padding = '30px 40px';
    hudContent.style.borderRadius = '12px';
    hudContent.style.maxWidth = '70%';
    hudContent.style.minWidth = '130px';
    hudContent.style.aspectRatio = "1";
    hudContent.style.display = 'flex';
    hudContent.style.flexDirection = 'column';
    hudContent.style.gap = '16px';
        hudContent.style.alignItems = 'center';
        hudContent.style.justifyContent = 'center'; // 垂直居中
    hudContent.style.textAlign = 'center';
    hudContent.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.2)';

    // 创建旋转菊花动画
    const spinner = document.createElement('div');
    spinner.style.width = '40px';
    spinner.style.height = '40px';
    spinner.style.border = '4px solid rgba(0, 0, 0, 0.1)';
    spinner.style.borderRadius = '50%';
    spinner.style.borderTop = '4px solid #3498db';
    spinner.style.animation = 'spin 1s linear infinite';

    // 添加动画关键帧
    const styleTag = document.createElement('style');
    styleTag.textContent = `
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    `;
    document.head.appendChild(styleTag);

    // 创建文字容器
    const textElement = document.createElement('div');
    textElement.textContent = message || '加载中...';
    textElement.style.fontSize = '16px';
    textElement.style.color = '#333';

    // 组合元素
    hudContent.appendChild(spinner);
    hudContent.appendChild(textElement);
    hudContainer.appendChild(hudContent);
    document.body.appendChild(hudContainer);

    // 自动隐藏
    const hideToast = () => {
        hudContainer.style.opacity = '0';
        setTimeout(() => {
            document.body.removeChild(hudContainer);
            document.head.removeChild(styleTag); // 移除动画样式
        }, 300);
    };

    let timeoutId = setTimeout(hideToast, duration);

    // 返回关闭方法
    return {
        close: () => {
            clearTimeout(timeoutId);
            hideToast();
        }
    };
}